package com.izhengyin.miaosha;

import org.springframework.scheduling.concurrent.CustomizableThreadFactory;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

final public class CreateOrderExecutor {
    private final static int MAX_QUEUE_SIZE = 200;
    private final static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(
            20,
            30,
            10L,
            TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(MAX_QUEUE_SIZE),
            new CustomizableThreadFactory("createOrderWorker-"),
            new ThreadPoolExecutor.AbortPolicy());

    public static int getMaxQueueSize(){
        return MAX_QUEUE_SIZE;
    }

    public static ThreadPoolExecutor getExecutor(){
        return EXECUTOR;
    }
}
